package appserver;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;

public class AppServerThread extends Thread{
	private final Socket socket;
	
	public static final int OP_SUM = 0;
	public static final int OP_MIN = 1;
	public static final int OP_MUL = 2;
	public static final int OP_DIV = 3;
	
	public AppServerThread(Socket socket){
		this.socket= socket;
	}
	
	public void run(){
		try {
			DataOutputStream out		= new DataOutputStream(socket.getOutputStream());
			DataInputStream in			= new DataInputStream(socket.getInputStream());
			
			Calculadora calc = new Calculadora(in);
			switch(calc.getOperacao()){
				case OP_SUM:
					calc.somar();
					break;
					
				case OP_MIN:
					calc.subtrair();
					break;
					
				case OP_DIV:
					calc.dividir();
					break;
					
				case OP_MUL:
					calc.multiplicar();
					break;
			
				default:
					break;
			
			}
			
			calc.enviar(out);
			
			out.close();
			in.close();
			socket.close();
			
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		
	}

}
